package org.hilo.boot.core.logback;

import java.io.Serializable;

import org.apache.juli.logging.Log;
import org.slf4j.LoggerFactory;
import org.slf4j.spi.LocationAwareLogger;

/**
 * 
 * @author zollty
 * @since 2022年7月18日
 */
public class Slf4jLocationAwareLogger extends Slf4jLogger<LocationAwareLogger>
        implements Log, Serializable {
    private static final long serialVersionUID = -4057985095053260197L;
    private static final String FQCN = Slf4jLocationAwareLogger.class.getName();

    public Slf4jLocationAwareLogger() {
    }
    
    public Slf4jLocationAwareLogger(String name) {
        super((LocationAwareLogger) LoggerFactory.getLogger(name));
    }

    public Slf4jLocationAwareLogger(LocationAwareLogger logger) {
        super(logger);
    }

    @Override
    public void fatal(Object message) {
        error(message);
    }

    @Override
    public void fatal(Object message, Throwable exception) {
        error(message, exception);
    }

    @Override
    public void error(Object message) {
        if (message instanceof String || this.logger.isErrorEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message),
                    null, null);
        }
    }

    @Override
    public void error(Object message, Throwable exception) {
        if (message instanceof String || this.logger.isErrorEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message),
                    null, exception);
        }
    }

    @Override
    public void warn(Object message) {
        if (message instanceof String || this.logger.isWarnEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null,
                    null);
        }
    }

    @Override
    public void warn(Object message, Throwable exception) {
        if (message instanceof String || this.logger.isWarnEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null,
                    exception);
        }
    }

    @Override
    public void info(Object message) {
        if (message instanceof String || this.logger.isInfoEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null,
                    null);
        }
    }

    @Override
    public void info(Object message, Throwable exception) {
        if (message instanceof String || this.logger.isInfoEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null,
                    exception);
        }
    }

    @Override
    public void debug(Object message) {
        if (message instanceof String || this.logger.isDebugEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message),
                    null, null);
        }
    }

    @Override
    public void debug(Object message, Throwable exception) {
        if (message instanceof String || this.logger.isDebugEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message),
                    null, exception);
        }
    }

    @Override
    public void trace(Object message) {
        if (message instanceof String || this.logger.isTraceEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message),
                    null, null);
        }
    }

    @Override
    public void trace(Object message, Throwable exception) {
        if (message instanceof String || this.logger.isTraceEnabled()) {
            this.logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message),
                    null, exception);
        }
    }

    @Override
    protected Object readResolve() {
        return new Slf4jLocationAwareLogger(
                (LocationAwareLogger) LoggerFactory.getLogger(this.name));
    }

}
